/*
 * @Author: 徐建辰
 * @Date: 2021-11-03 16:32:40
 * @LastEditTime: 2021-11-04 15:20:11
 * @LastEditors: Please set LastEditors
 * @Description: 首页日期选择组件
 */
import React, {useMemo} from 'react'
import dayjs from 'dayjs'
import PropTypes from 'prop-types'
import {formatTime} from '@/utils/format'
import './departdate.css'
export default function DepartDate(props) {
  const {time, onClickDate} = props
  //获取日期的格式：2020-1-1的格式
  const hOfDepart = formatTime(time)
  // eslint-disable-next-line react-hooks/exhaustive-deps
  const dateStr = useMemo(() => dayjs(time).format('YYYY-MM-DD'), [hOfDepart])
  const departDate = new Date(hOfDepart)
  const isToday = hOfDepart === formatTime()
  const weekStr = `周${['日', '一', '二', '三', '四', '五', '六'][departDate.getDay()]}${isToday ? '(今天)' : ''}`
    
  return (
    <div className="depart-date" onClick={onClickDate}>
      <input type="hidden" name="date" value={dateStr}/>
      {dateStr} <span className="depart-week">{weekStr}</span>
    </div>
  )
}

DepartDate.propTypes = {
  time: PropTypes.number.isRequired,
  onClickDate: PropTypes.func.isRequired,
}

